package top.psjj.mall.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.psjj.mall.filter.AdminFilter;
import top.psjj.mall.filter.UserFilter;

@Configuration
public class FilterConfig {
    @Bean
    public AdminFilter adminFilter(){
        return new AdminFilter();
    }
    @Bean
    public FilterRegistrationBean filterRegistrationBean( AdminFilter adminFilter){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(adminFilter);
        filterRegistrationBean.addUrlPatterns("/admin/category/*");
        filterRegistrationBean.addUrlPatterns("/admin/product/*");
        filterRegistrationBean.addUrlPatterns("/admin/upload/file");
        return filterRegistrationBean;
    }
    @Bean
    public UserFilter userFilter(){
        return new UserFilter();
    }
    @Bean
    public FilterRegistrationBean filterRegistrationBean2(@Autowired UserFilter userFilter){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(userFilter);
        filterRegistrationBean.addUrlPatterns("/cart/*");
        filterRegistrationBean.addUrlPatterns("/order/*");
        return filterRegistrationBean;
    }

}

